
demolitionOrders()
function demolitionOrders(){
	var demolitionOrdertable=""
	$.ajax({
		type: "POST",
		url: root.orderInter.queryOrderSplitDetails,
		cache: false, //禁用缓存
		dataType: "json",
		data: {
			order_id: sessionStorage.getItem("demolitionOrderId"), // 订单编号
		},
		success: function (result) {
			//表格
			var arr=result.data.splitProductVOList
			$.each(arr,function(k,v){

				var warehouses=JSON.parse(sessionStorage.getItem("warehouses"))
				var warehouse=""
				$.each(warehouses.data,function(k,s){
					if(result.data.parent_warehouse_id==s.warehouseCode){
						warehouse=s.warehouseName
					}
				})
				var abnormalCauses=""//异常原因

				if(v.spuId ==0){
					//临采
					abnormalCauses+="临采商品<br>"
					if(v.occupyVirtualStore >0){
						//超卖
						abnormalCauses+='超卖商品<br>'
					}
					if(Number(v.price)*Number(v.buyyerCount) < Number(v.costPrice)*Number(v.buyyerCount) ){
						//低于成本价
						abnormalCauses+="低于成本价商品<br>"
					}
				}else {
					if(v.occupyVirtualStore >0){
						//超卖
						abnormalCauses+='超卖商品<br>'
					}
					if(Number(v.price)*Number(v.buyyerCount) < Number(v.costPrice)*Number(v.buyyerCount) ){
						//低于成本价
						abnormalCauses+="低于成本价商品<br>"
					}
					if(Number(v.manufacturerSentLimit)!=0){
						if(v.subtotalPrice > Number(v.manufacturerSentLimit) || v.subtotalPrice == Number(v.manufacturerSentLimit)){
							//厂家直送商品
							abnormalCauses+="厂家直送商品<br>"
						}
					}

				}



				v.storeStock = v.storeStock == null ? '' : v.storeStock
                    //表格
                demolitionOrdertable += '<tr class="tables" >' +
                    '                            <td class="demolitionOrder_1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.productPic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.productCode + '</div><div>' + v.productName + '</div><div>' + v.color + '</div><div>' + v.skuAttributeInfo + '</div></div></div></td>' +
                    '                            <td class="demolitionOrder_2">' + warehouse + '</td>' +
                    '                            <td class="demolitionOrder_3"><input type="text" class="input-text mr-5" oninput="divisibleQuantity(this,' + v.buyyerCount + ',' + v.alreadySplitNum + ')" onclick="divisibleQuantity(this,' + v.buyyerCount + ',' + v.alreadySplitNum + ')" style="width: 43px;" value=""></td>' +
                    '                            <td class="demolitionOrder_4">' + v.alreadySplitNum + '</td>' +
                    '                            <td class="demolitionOrder_5">' + v.buyyerCount + '' + v.unitName + '</td>' +
                    '                            <td class="demolitionOrder_6">' + v.actualStock + '</td>' +
                    '                            <td class="demolitionOrder_7">' + v.storeStock + '</td>' +
                    '                            <td class="demolitionOrder_8">' + v.price.toFixed(2) + '元/' + v.unitName + '</td>' +
                    '                            <td class="demolitionOrder_9" style="display: none">' + v.productCode + '</td>' +
                    '							<td class="demolitionOrder_10" style="display: none">' + v.buyyerCount + '</td>' +
                    '							<td class="demolitionOrder_11" >' + abnormalCauses + '</td>' +
                    '                    </tr>'


            })
			$("#datatable").find("tbody").html($(demolitionOrdertable));
		},
	});
}
//刷新实际库存
function refresh() {
	$.ajax({
		type: "POST",
		url: root.orderInter.queryOrderSplitDetails,
		cache: false, //禁用缓存
		dataType: "json",
		data: {
			order_id: sessionStorage.getItem("demolitionOrderId"), // 订单编号
		},
		success: function (result) {
			if(result.errorCode==0){
				$.Huimodalalert("刷新成功",2000);
				var productList = $('.shun').find('.demolitionOrder_6');
				var productList01 = $('.shun').find('.demolitionOrder_7');
				for (var j = 0; j < result.data.splitProductVOList.length; j++) {
					$(productList[j]).text( result.data.splitProductVOList[j].actualStock)
					result.data.splitProductVOList[j].storeStock == null ? $(productList01[j]).text('') : $(productList01[j]).text(result.data.splitProductVOList[j].storeStock)
				}
			}else {
				$.Huimodalalert(result.msg,2000);
			}



		},
	});
}
//可拆分数量效验
function divisibleQuantity(val,buyyerCount,alreadySplitNum) {
    var divisibleQuantitys=Number(buyyerCount)-Number(alreadySplitNum)
    //需要<=购买数量-已拆分数量的总和。如果超出，不允许录入
    if(Number($(val).val())>Number(divisibleQuantitys)){
        $(val).val("")
        $.Huimodalalert('输入数值错误',2000);

    }
    //判断购买数量是整数还是小数
    var buyyerCountstr = buyyerCount+"";
    if(buyyerCountstr.indexOf(".")==-1){
        //"整数"
        //(只能输入数字)
        val.value = val.value.replace(/[^\d]/g,""); //清除"数字"和"."以外的字符
        val.value = val.value.replace(/^\./g,""); //验证第一个字符是数字
		/*val.value=val.value.replace(/[^1-9-]+/,'');*/
		if($(val).val()!=""){
			if(Number($(val).val())<=0){
				$(val).val("")
				$.Huimodalalert('输入数值错误',2000);
			}
		}

    }else{
       //"小数"
        //(可输入小数点)
        val.value = val.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
        val.value = val.value.replace(/^\./g,""); //验证第一个字符是数字
        val.value = val.value.replace(/\.{2,}/g,""); //只保留第一个, 清除多余的
        val.value = val.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        //只能等于购买数量
		$(val).val(buyyerCount)

    }

}

//生成子订单
function generate() {
	var splitOrderdata={}
	var productList = $('#datatable tr ');
	var maop=[]
	var plm={}
	for(var j=0;j<productList.length;j++) {
		if($(productList[j]).find('.demolitionOrder_3 input').val()!=""&&$(productList[j]).find('.demolitionOrder_3 input').val()!=undefined){
			plm = {
				"product_code": $(productList[j]).find('.demolitionOrder_9').text(),
				"split_num": $(productList[j]).find('.demolitionOrder_3 input').val(),

			}
			maop.push(plm)
		}
	}
	if(maop==""){
		$.Huimodalalert("请填写数量",2000);
		splitOrderdata={
			"order_id":sessionStorage.getItem("demolitionOrderId"),
			"operator_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
			"operator_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
			"deal_account":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number
		}
	}else {
		splitOrderdata={
			"order_id":sessionStorage.getItem("demolitionOrderId"),
			"operator_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
			"operator_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
			"productList": maop,
			"deal_account":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number
		}
	}
    $.ajax({
        type: "POST",
        url:root.orderInter.splitOrder ,
        cache: false,  //禁用缓存
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify(splitOrderdata),
        success: function (result) {
        	if (result.errorCode==0){
				$.Huimodalalert("生成子订单成功",2000);
				demolitionOrders()
			}else {
				$.Huimodalalert(result.msg,2000);
			}
        },
    });

}
//收货信息
function receiving() {
	layer_show("收货信息", "demolitionOrder_details.html", "600", "300");
	sessionStorage.setItem("demolitionOrderId",sessionStorage.getItem("demolitionOrderId"))
}

//自动计算
function calculation() {
	var datasList = $('#datas tr');
	var demolitionOrderval=""
	datasList.each(function (index,dom) {
		demolitionOrderval=$(dom).find('td.demolitionOrder_10').html()-$(dom).find('td.demolitionOrder_4').html()
		$(dom).find('td.demolitionOrder_3 input').val(demolitionOrderval)
	})
}
//厂家直送
function manufactor() {
	var datasList = $('#datas tr');
	var demolitionOrderval=""
	datasList.each(function (index,dom) {
		if($(dom).find('td.demolitionOrder_11').html().indexOf("厂家直送商品")!=-1){
			demolitionOrderval=$(dom).find('td.demolitionOrder_10').html()-$(dom).find('td.demolitionOrder_4').html()
			$(dom).find('td.demolitionOrder_3 input').val(demolitionOrderval)
		}

	})
}